/*
 * Copyright 2003-2006 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */
 

%include typemaps/swigmacros.swg
%include attribute.i

%define %_my_attribute(Class, Wrap, type, attr, getcode, setcode) 
	%extend Class {
	  type attr;
	}
	%{
	#define Wrap ##_## attr ## _get(self) getcode(self)
	#define Wrap ##_## attr ## _set(self, _val) setcode(self, _val)
	%}
%enddef

%define %_my_attribute_readonly(Class, Wrap, type, attr, getcode) 
	%extend Class {
	  type attr;
	}
	%{
	#define Wrap ##_## attr ## _get(self) getcode(self)
	#define Wrap ##_## attr ## _set(self, _val) %attribute_exception(SWIG_AttributeError,"read-only  'attr' attribute");
	%}
%enddef


%define %add_prop(class, type, name, getter, setter)
	%_my_attribute(%arg(class), %mangle(class), %arg(type), name, getter, setter)
%enddef


%define %add_readonly_prop(class, type, name, getter)
	%_my_attribute_readonly(%arg(class), %mangle(class), %arg(type), name, getter)
%enddef


%define %fix_naming_to(oldname, newname)
	%rename(newname) oldname;
%enddef



%define %add_bound_method(klass, return_type, funcnameNew, funcnameOld, ...)

%extend klass
{
	%{
		#define klass##_##funcnameNew funcnameOld
	%}
	return_type funcnameNew(##__VA_ARGS__);
}

%enddef

// example: %add_bound_method(test_library, int, get_state, test_library_get_state, int param1, double param2)


%define %add_static_bound_method(klass, return_type, funcnameNew, funcnameOld, ...)

%extend klass
{
	%{
		#define klass##_##funcnameNew funcnameOld
	%}
	static return_type funcnameNew(__VA_ARGS__);
}

%enddef



%define %set_constructor_3(type, func, type1, arg1, type2, arg2, type3, arg3) 
%extend type
{
	type(type1 arg1, type2 arg2, type3 arg3)
	{
		type* self = calloc(1, sizeof(type));
		func(self, arg1, arg2, arg3);
		return self;
	}
}
%enddef

%define %set_constructor_2(type, func, type1, arg1, type2, arg2) 
%extend type
{
	type(type1 arg1, type2 arg2)
	{
		type* self = calloc(1, sizeof(type));
		func(self, arg1, arg2);
		return self;
	}
}
%enddef

%define %set_constructor_1(type, func, type1, arg1) 
%extend type
{
	type(type1 arg1)
	{
		type* self = calloc(1, sizeof(type));
		func(self, arg1);
		return self;
	}
}
%enddef

%define %set_constructor_0(type, func) 
%extend type
{
	type()
	{
		type* self = calloc(1, sizeof(type));
		func(self);
		return self;
	}
}
%enddef

%define %set_destructor(type, func)

%extend type
{
	~type()
	{
		func(self);
		free((char *)self);
	}
}

%enddef